<template>
  <div>
    <el-select v-model="value" placeholder="请选择" @change="setType(value)">
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <el-input
      v-model="input"
      placeholder="请输入内容"
      @input="setValue(input)"
    ></el-input>
    <el-button type="primary" icon="el-icon-search" @click="getCustomers"
      >搜索</el-button
    >
    <el-table :data="customers" border style="width: 100%">
      <el-table-column fixed prop="_id" label="客户编号" width="250">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="170"> </el-table-column>
      <el-table-column prop="age" label="年龄" width="170"> </el-table-column>
      <el-table-column prop="gender" label="性别" width="170">
      </el-table-column>
      <el-table-column prop="phone" label="电话" width="170"> </el-table-column>
      <el-table-column prop="salesMenId.name" label="负责人" width="170">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="130">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="delet(scope.row._id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[3, 5, 7, 9]"
        :page-size="3"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total - 0"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
  'Customers'
)
export default {
  data() {
    return {
      type: 'name',
      options: [
        {
          value: 'name',
          label: '姓名',
        },
        {
          value: 'age',
          label: '年龄',
        },
        {
          value: 'gender',
          label: '性别',
        },
        {
          value: 'phone',
          label: '电话',
        },
      ],
      value: '',
      input: '',
    }
  },
  mounted() {
    this.getCustomers()
  },
  computed: {
    ...mapState(['customers', 'pageSize', 'cutPage', 'total', 'totalPage']),
  },
  methods: {
    ...mapActions(['getCustomers', 'delCustomers']),
    ...mapMutations(['setPageSize', 'setCutPage', 'setType', 'setValue']),
    handleSizeChange(val) {
      this.setPageSize(val)
      this.getCustomers()
    },
    handleCurrentChange(val) {
      this.setCutPage(val)
      this.getCustomers()
    },
    delet(_id) {
      this.delCustomers(_id), this.getCustomers()
    },
  },
}
</script>

<style scoped>
.el-select {
  float: left;
  width: 100px;
}
.el-select .el-input {
  width: 100%;
}
.el-input {
  width: 20%;
  float: left;
}
.el-button {
  float: left;
}
</style>
